package tv.danmaku.ijk.media.player;

import android.annotation.TargetApi;
import android.media.MediaCodecInfo.CodecCapabilities;
import android.media.MediaCodecInfo.CodecProfileLevel;
import android.media.MediaCodecInfo;
import android.os.Build;
import android.text.TextUtils;
import android.util.Log;
import java.util.Locale;
import java.util.Map;
import java.util.TreeMap;

public class IjkMediaCodecInfo {
    public static final int RANK_ACCEPTABLE = 700;
    public static final int RANK_LAST_CHANCE = 600;
    public static int RANK_MAX = 0;
    public static final int RANK_NON_STANDARD = 100;
    public static final int RANK_NO_SENSE = 0;
    public static final int RANK_SECURE = 300;
    public static final int RANK_SOFTWARE = 200;
    public static final int RANK_TESTED = 800;
    private static final String TAG = "IjkMediaCodecInfo";
    public MediaCodecInfo mCodecInfo;
    public String mMimeType;
    public int mRank;
    private static Map sKnownCodecList;

    static {
        IjkMediaCodecInfo.RANK_MAX = 1000;
    }

    public IjkMediaCodecInfo() {

        this.mRank = 0;
    }

    @TargetApi(value=16) public void dumpProfileLevels(String arg8) {
        int v1_1;
        int v0 = 0;
        if(Build.VERSION.SDK_INT >= 16) {
            try {
                CodecCapabilities v1 = this.mCodecInfo.getCapabilitiesForType(arg8);
                if(v1 == null || v1.profileLevels == null) {
                    v1_1 = 0;
                }
                else {
                   CodecProfileLevel[] v3 = v1.profileLevels;
                    int v4 = v3.length;
                    int v2 = 0;
                    v1_1 = 0;
                    while(v2 < v4) {
                        CodecProfileLevel v5 = v3[v2];
                        if(v5 != null) {
                            v1_1 = Math.max(v1_1, v5.profile);
                            v0 = Math.max(v0, v5.level);
                        }

                        ++v2;
                    }
                }

                Log.i("IjkMediaCodecInfo", String.format(Locale.US, "%s", IjkMediaCodecInfo.getProfileLevelName(v1_1, v0)));
            }
            catch(Throwable v0_1) {
                Log.i("IjkMediaCodecInfo", "profile-level: exception");
            }
        }
    }

    private static synchronized Map getKnownCodecList() {
        Map v0_1;
        if (IjkMediaCodecInfo.sKnownCodecList != null) {
            v0_1 = IjkMediaCodecInfo.sKnownCodecList;
        } else {
            TreeMap v0_2 = new TreeMap(String.CASE_INSENSITIVE_ORDER);
            IjkMediaCodecInfo.sKnownCodecList = ((Map) v0_2);
            ((Map) v0_2).put("OMX.Nvidia.h264.decode", Integer.valueOf(800));
            IjkMediaCodecInfo.sKnownCodecList.put("OMX.Nvidia.h264.decode.secure", Integer.valueOf(300));
            IjkMediaCodecInfo.sKnownCodecList.put("OMX.Intel.hw_vd.h264", Integer.valueOf(801));
            IjkMediaCodecInfo.sKnownCodecList.put("OMX.Intel.VideoDecoder.AVC", Integer.valueOf(800));
            IjkMediaCodecInfo.sKnownCodecList.put("OMX.qcom.video.decoder.avc", Integer.valueOf(800));
            IjkMediaCodecInfo.sKnownCodecList.put("OMX.ittiam.video.decoder.avc", Integer.valueOf(0));
            IjkMediaCodecInfo.sKnownCodecList.put("OMX.SEC.avc.dec", Integer.valueOf(800));
            IjkMediaCodecInfo.sKnownCodecList.put("OMX.SEC.AVC.Decoder", Integer.valueOf(799));
            IjkMediaCodecInfo.sKnownCodecList.put("OMX.SEC.avcdec", Integer.valueOf(798));
            IjkMediaCodecInfo.sKnownCodecList.put("OMX.SEC.avc.sw.dec", Integer.valueOf(200));
            IjkMediaCodecInfo.sKnownCodecList.put("OMX.Exynos.avc.dec", Integer.valueOf(800));
            IjkMediaCodecInfo.sKnownCodecList.put("OMX.Exynos.AVC.Decoder", Integer.valueOf(799));
            IjkMediaCodecInfo.sKnownCodecList.put("OMX.k3.video.decoder.avc", Integer.valueOf(800));
            IjkMediaCodecInfo.sKnownCodecList.put("OMX.IMG.MSVDX.Decoder.AVC", Integer.valueOf(800));
            IjkMediaCodecInfo.sKnownCodecList.put("OMX.TI.DUCATI1.VIDEO.DECODER", Integer.valueOf(800));
            IjkMediaCodecInfo.sKnownCodecList.put("OMX.rk.video_decoder.avc", Integer.valueOf(800));
            IjkMediaCodecInfo.sKnownCodecList.put("OMX.amlogic.avc.decoder.awesome", Integer.valueOf(800));
            IjkMediaCodecInfo.sKnownCodecList.put("OMX.MARVELL.VIDEO.HW.CODA7542DECODER", Integer.valueOf(800));
            IjkMediaCodecInfo.sKnownCodecList.put("OMX.MARVELL.VIDEO.H264DECODER", Integer.valueOf(200));
            IjkMediaCodecInfo.sKnownCodecList.remove("OMX.Action.Video.Decoder");
            IjkMediaCodecInfo.sKnownCodecList.remove("OMX.allwinner.video.decoder.avc");
            IjkMediaCodecInfo.sKnownCodecList.remove("OMX.BRCM.vc4.decoder.avc");
            IjkMediaCodecInfo.sKnownCodecList.remove("OMX.brcm.video.h264.hw.decoder");
            IjkMediaCodecInfo.sKnownCodecList.remove("OMX.brcm.video.h264.decoder");
            IjkMediaCodecInfo.sKnownCodecList.remove("OMX.cosmo.video.decoder.avc");
            IjkMediaCodecInfo.sKnownCodecList.remove("OMX.duos.h264.decoder");
            IjkMediaCodecInfo.sKnownCodecList.remove("OMX.hantro.81x0.video.decoder");
            IjkMediaCodecInfo.sKnownCodecList.remove("OMX.hantro.G1.video.decoder");
            IjkMediaCodecInfo.sKnownCodecList.remove("OMX.hisi.video.decoder");
            IjkMediaCodecInfo.sKnownCodecList.remove("OMX.LG.decoder.video.avc");
            IjkMediaCodecInfo.sKnownCodecList.remove("OMX.MS.AVC.Decoder");
            IjkMediaCodecInfo.sKnownCodecList.remove("OMX.RENESAS.VIDEO.DECODER.H264");
            IjkMediaCodecInfo.sKnownCodecList.remove("OMX.RTK.video.decoder");
            IjkMediaCodecInfo.sKnownCodecList.remove("OMX.sprd.h264.decoder");
            IjkMediaCodecInfo.sKnownCodecList.remove("OMX.ST.VFM.H264Dec");
            IjkMediaCodecInfo.sKnownCodecList.remove("OMX.vpu.video_decoder.avc");
            IjkMediaCodecInfo.sKnownCodecList.remove("OMX.WMT.decoder.avc");
            IjkMediaCodecInfo.sKnownCodecList.remove("OMX.bluestacks.hw.decoder");
            IjkMediaCodecInfo.sKnownCodecList.put("OMX.google.h264.decoder", Integer.valueOf(200));
            IjkMediaCodecInfo.sKnownCodecList.put("OMX.google.h264.lc.decoder", Integer.valueOf(200));
            IjkMediaCodecInfo.sKnownCodecList.put("OMX.k3.ffmpeg.decoder", Integer.valueOf(200));
            IjkMediaCodecInfo.sKnownCodecList.put("OMX.ffmpeg.video.decoder", Integer.valueOf(200));
            IjkMediaCodecInfo.sKnownCodecList.put("OMX.sprd.soft.h264.decoder", Integer.valueOf(200));
            v0_1 = IjkMediaCodecInfo.sKnownCodecList;
        }
        return v0_1;
    }

    public static String getLevelName(int arg1) {
        String v0;
        switch(arg1) {
            case 1: {
                v0 = "1";
                break;
            }
            case 2: {
                v0 = "1b";
                break;
            }
            case 4: {
                v0 = "11";
                break;
            }
            case 8: {
                v0 = "12";
                break;
            }
            case 16: {
                v0 = "13";
                break;
            }
            case 32: {
                v0 = "2";
                break;
            }
            case 64: {
                v0 = "21";
                break;
            }
            case 128: {
                v0 = "22";
                break;
            }
            case 256: {
                v0 = "3";
                break;
            }
            case 512: {
                v0 = "31";
                break;
            }
            case 1024: {
                v0 = "32";
                break;
            }
            case 2048: {
                v0 = "4";
                break;
            }
            case 4096: {
                v0 = "41";
                break;
            }
            case 8192: {
                v0 = "42";
                break;
            }
            case 16384: {
                v0 = "5";
                break;
            }
            case 32768: {
                v0 = "51";
                break;
            }
            case 65536: {
                v0 = "52";
                break;
            }
            default: {
                v0 = "0";
                break;
            }
        }

        return v0;
    }

    public static String getProfileLevelName(int arg5, int arg6) {
        return String.format(Locale.US, " %s Profile Level %s (%d,%d)",
                IjkMediaCodecInfo.getProfileName(arg5),
                IjkMediaCodecInfo.getLevelName(arg6),
                Integer.valueOf(arg5), Integer.valueOf(arg6));
    }

    public static String getProfileName(int arg1) {
        String v0;
        switch(arg1) {
            case 1: {
                v0 = "Baseline";
                break;
            }
            case 2: {
                v0 = "Main";
                break;
            }
            case 4: {
                v0 = "Extends";
                break;
            }
            case 8: {
                v0 = "High";
                break;
            }
            case 16: {
                v0 = "High10";
                break;
            }
            case 32: {
                v0 = "High422";
                break;
            }
            case 64: {
                v0 = "High444";
                break;
            }
            default: {
                v0 = "Unknown";
                break;
            }
        }

        return v0;
    }

    @TargetApi(value=16) public static IjkMediaCodecInfo setupCandidate(MediaCodecInfo arg6, String arg7) {
        IjkMediaCodecInfo v3 = null;
        int v2 = 600;
        int v0 = 200;
        if(arg6 != null && Build.VERSION.SDK_INT >= 16) {
            String v4 = arg6.getName();
            if(TextUtils.isEmpty(v4)) {
                IjkMediaCodecInfo v0_1 = v3;
                return v0_1;
            }
            else {
                String v3_1 = v4.toLowerCase(Locale.US);
                if(!v3_1.startsWith("omx.")) {
                    v0 = 100;
                } else if((v3_1.startsWith("omx.pv")) || (v3_1.startsWith("omx.google.")) || (v3_1.startsWith("omx.ffmpeg.")) || (v3_1.startsWith("omx.k3.ffmpeg.")) || (v3_1.startsWith("omx.avcodec."))) {
                } else if(v3_1.startsWith("omx.ittiam.")) {
                    v0 = 0;
                } else {
                    if(!v3_1.startsWith("omx.mtk.")) {
                        Object v0_2 = IjkMediaCodecInfo.getKnownCodecList().get(v3_1);
                        if(v0_2 != null) {
                            v0 = ((Integer)v0_2).intValue();
                        } else {
                                if(arg6.getCapabilitiesForType(arg7) == null) {
                                    v0 = v2;
                                }else {
                                    v0 = 700;
                                }
                        }
                    } else if(Build.VERSION.SDK_INT < 18) {
                        v0 = 0;
                    } else {
                        v0 = 800;
                    }
                }

                IjkMediaCodecInfo v1 = new IjkMediaCodecInfo();
                v1.mCodecInfo = arg6;
                v1.mRank = v0;
                v1.mMimeType = arg7;
                return v1;
            }
        }

        return v3;
    }
}

